package com.sskj.api.handler.serializer;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.sskj.common.util.StrUtil;

import java.io.IOException;

public class WithDomainDeserializer extends JsonDeserializer<String> {

    private final String domain;

    public WithDomainDeserializer(String domain) {
        this.domain = domain;
    }

    @Override
    public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
        String url = jsonParser.getValueAsString();
        if (StrUtil.isBlank(url)) {
            return null;
        }
        return url.replace(domain, "");
    }
}
